using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;


namespace DAO
{
    public static class SachDAO
    {
        public static bool themsach(SachDTO sdto)
        {
            string sql = "insert into Sach(TenSach,Soluong,MaTG,Maloai) values('" + sdto.TenSach + "'," + sdto.Soluong + ",'" + sdto.MaTG + "','" + sdto.Maloai + "')";
            return DataProvider.ExecuteNonQuery(sql);
        }

        public static int laymasach()
        {
            string sql = "select max(MaSach) from Sach";

            OleDbCommand cmd = new OleDbCommand(sql, DataProvider.ketnoi());
            int maphieu = (int)cmd.ExecuteScalar();
            int maphieumoi = maphieu + 1;
            return maphieumoi;


        }
        public static bool updatesach(SachDTO sdto)
        {
            try
            {
                string sql = "update Sach set Tensach='" + sdto.TenSach + "',Soluong=" + sdto.Soluong + ",MaTG='" + sdto.MaTG + "',Maloai='" + sdto.Maloai + "' where MaSach=" + sdto.MaSach + "";
                return DataProvider.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public static bool xoasach(SachDTO sdto)
        {
            string sql = "delete from Sach where MaSach=" + sdto.MaSach + "";
            return DataProvider.ExecuteNonQuery(sql);
        }
    }
}
